package pl.gettoknowme.mobile.android.services.sms;

import java.sql.Date;

/**
 * Reprezentacja wiadomości SMS
 * @author Michał Kołodziejski
 */
public class SmsMessage {

    public enum MessageType {
        MESSAGE_TYPE_ALL,
        MESSAGE_TYPE_INBOX,
        MESSAGE_TYPE_SENT,
        MESSAGE_TYPE_DRAFT,
        MESSAGE_TYPE_OUTBOX,
        MESSAGE_TYPE_FAILED,
        MESSAGE_TYPE_QUEUED;
        
        public static MessageType forInt(int typeId){
            switch (typeId) {
            case 0:
                return MESSAGE_TYPE_ALL;
            case 1:
                return MESSAGE_TYPE_INBOX;
            case 2:
                return MESSAGE_TYPE_SENT;
            case 3:
                return MESSAGE_TYPE_DRAFT;
            case 4:
                return MESSAGE_TYPE_OUTBOX;
            case 5:
                return MESSAGE_TYPE_FAILED;
            case 6:
                return MESSAGE_TYPE_QUEUED;
            default:
                return MESSAGE_TYPE_ALL;
            }
        }
    }

    protected long messageId;
    protected MessageType messageType;
    protected String address;
    protected String body;
    protected long timestamp;
    
    public SmsMessage() {
    }

    public SmsMessage(long messageId, MessageType messageType, String address, 
            String body, long timestamp) {
        this.messageId = messageId;
        this.messageType = messageType;
        this.address = address;
        this.body = body;
        this.timestamp = timestamp;
    }

    public long getMessageId() {
        return messageId;
    }

    public void setMessageId(long messageId) {
        this.messageId = messageId;
    }

    public MessageType getMessageType() {
        return messageType;
    }

    public void setMessageType(MessageType messageType) {
        this.messageType = messageType;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }
    
    @Override
    public String toString() {
        return "SmsMessage["
            +"type: " + messageType.toString()
            +", address: " + address
            +", body: "+body
            +", timestamp: "+timestamp
            +", date: "+new Date(timestamp)
            +"]";
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + (int) (messageId ^ (messageId >>> 32));
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof SmsMessage)) {
            return false;
        }
        SmsMessage other = (SmsMessage) obj;
        if (messageId != other.messageId) {
            return false;
        }
        return true;
    }
}
